﻿
using DG.Tweening;
using QFramework;
using UnityEngine;
using UnityEngine.Tilemaps;

namespace ProjectChildhood
{
    public class ToolShovel : ITool
    {
        public string Name => "铁锹";

        public int Range => Global.ShovelUpgradeUnlock ? 2 : 1;

        public bool Selectable(ToolData toolData)
        {
            return toolData.ShowGrid[toolData.CellPos.x, toolData.CellPos.y] == null;
        }

        public void Use(ToolData toolData)
        {
            toolData.SoilTilemap.SetTile(new Vector3Int(toolData.CellPos.x, toolData.CellPos.y), toolData.Pen);
            toolData.ShowGrid[toolData.CellPos.x, toolData.CellPos.y] = new SoilData();
            AudioController.Instance.SFX_DigWithShovel.Play();

            ToolController toolController = Object.FindObjectOfType<ToolController>();
            Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            toolController.Fx_Digging.Position(mousePos.x, mousePos.y);
            toolController.Fx_Digging.GetComponent<ParticleSystem>().Play(); // 挖掘的粒子特效
            CameraController.Shake(CameraController.EShakeType.Heavy); // 摄像机震动效果
        }
    }
}
